﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Antu.WebControls;
using Antu.Core.Components;
using Antu.Core.Services;
using System.Web.UI.WebControls;
using EluZSProvider;
using System.Data;

namespace WebSys.UI
{
    public partial class ZJ_ZJKHSQQK : Page
    {
        EluZSDataProvider _EluZSDataProvider = (EluZSDataProvider)ProviderService.ProviderServiceMange.GetProvider("EluZSProvider");
        #region 页面元素
        protected global::System.Web.UI.HtmlControls.HtmlForm form1;
        protected global::System.Web.UI.HtmlControls.HtmlTable table1;
        protected global::System.Web.UI.HtmlControls.HtmlTable table2;
        protected global::System.Web.UI.WebControls.DropDownList DropDownList1;
        protected global::Antu.WebControls.CustomGridView CustomGridView1;
        protected global::Antu.WebControls.CustomGridView CustomGridView2;
        #endregion
        public string strType = string.Empty;
        public string userId = string.Empty;
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            if (Session["UserID"] != null) { userId = Session["UserID"].ToString(); }
            strType = Request["type"];
            if (string.IsNullOrEmpty(strType)) { strType = "view"; }
            if (!IsPostBack) {
                if (strType == "doing")
                {
                    table1.Visible = true;
                    BindData();
                }
                else if (strType == "view")
                {
                    table2.Visible = true;
                    BindDll();
                    BindData1();
                }
            }
        }

        protected void CustomGridView2_OnLoadData(object sender, EventArgs e)
        {
            BindData1();
        }

        protected void CustomGridView1_OnLoadData(object sender, EventArgs e)
        {
            BindData();
        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            BindData1();
        }
        protected void BindData() 
        {
            string sql = @"select distinct t1.立项号,t1.项目名称,t.bcid,t.pid  from ZS_ZJKHSQ t,zs_project t1 where t.pid=t1.id 
and t.开户审核状态 in ('1','2') and t.pid not in (select pid from ZS_ZJKHSQ where pid =t.pid and 开户审核状态=3) ";
            DataTable dt = _EluZSDataProvider.GetOneDs("(" + sql + ")", "*", "").Tables[0];
            CustomGridView1.DataSource = dt;
            CustomGridView1.RecordCount = dt.Rows.Count;
            CustomGridView1.DataBind();
        }
        protected void BindData1()
        {
            string sql = @"select t1.立项号,t1.项目名称,t.bcid,t.pid,t.id,
(case when t.开户审核状态=0 then '未申请' 
when t.开户审核状态=1 then '已申请'
when t.开户审核状态=2 then '退回' 
when t.开户审核状态=3 then '审核通过' 
else null end ) 开户审核,
to_char(t.addtime,'yyyy-MM-dd hh24:mi:ss') 更新时间
from ZS_ZJKHSQ t,zs_project t1 where t.pid=t1.id ";
            if (!string.IsNullOrEmpty(DropDownList1.SelectedValue)) {
                sql += " and t.pid='" + DropDownList1.SelectedValue + "'";
            }
            sql += " order by t.addtime desc ";
            DataTable dt = _EluZSDataProvider.GetOneDs("(" + sql + ")", "*", "").Tables[0];
            CustomGridView2.DataSource = dt;
            CustomGridView2.RecordCount = dt.Rows.Count;
            CustomGridView2.DataBind();
        }
        protected void BindDll()
        {
            string sql = @"select distinct t1.项目名称,t.pid from ZS_ZJKHSQ t,zs_project t1 where t.pid=t1.id ";
            DataTable dt = _EluZSDataProvider.GetOneDs("(" + sql + ")", "*", "").Tables[0];
            //DataRow dr = dt.NewRow();
            //dt.Rows.InsertAt(dr, 0);
            DropDownList1.DataSource = dt;
            DropDownList1.DataValueField = "pid";
            DropDownList1.DataTextField = "项目名称";
            DropDownList1.DataBind();
        }
    }
}


